

<?php
session_start();
if(!isset($_SESSION['email'])) {
header('location:index.php'); }
else { $email = $_SESSION['email']; }
require_once("koneksi.php");


$jenis_id = $_POST['pembayaran'];
	if($jenis_id == 1) $jenis_nama = "Pertahun";
else 
	$jenis_nama = "Perbulan";


if (isset($_POST['jenis']))
$jenis = $_POST['jenis'];
if (isset($_POST['alamat']))
$alamat = $_POST['alamat'];
if (isset($_POST['kota']))
$kota_kabupaten = $_POST['kota'];
if (isset($_POST['propinsi']))
$propinsi_id = $_POST['propinsi'];
if (isset($_POST['fasilitas1']))
$fasilitas1 = $_POST['fasilitas1'];
if (isset($_POST['fasilitas2']))
$fasilitas2 = $_POST['fasilitas2'];
if (isset($_POST['fasilitas3']))
$fasilitas3 = $_POST['fasilitas3'];
if (isset($_POST['fasilitas4']))
$fasilitas4 = $_POST['fasilitas4'];
if (isset($_POST['banyakkamar']))
$banyakkamar = $_POST['banyakkamar'];
if (isset($_POST['banyakkamarmandi']))
$banyakkamarmandi = $_POST['banyakkamarmandi'];
if (isset($_POST['jenis_pembayaran']))
$jenis_id = $_POST['jenis_pembayaran'];
if (isset($_POST['harga']))
$harga = $_POST['harga'];
if (isset($_POST['keterangan']))
$keterangan = $_POST['keterangan'];
if (isset($_POST['judul_iklan']))
$judul_iklan = $_POST['judul_iklan'];
if (isset($_POST['panjang']))
$panjang = $_POST['panjang'];
if (isset($_POST['lebar']))
$lebar = $_POST['lebar'];

$kota = mysql_query("SELECT * FROM kota_kabupaten WHERE kota_kabupaten = '$kota_kabupaten'");
$hasil = mysql_fetch_array($kota);
$kota_id = $hasil['kota_id'];



if (isset($_FILES['foto1']['tmp_name']))
$lokasi_file = $_FILES['foto1']['tmp_name'];
if (isset($_FILES['foto1']['type']))
$tipe_file   = $_FILES['foto1']['type'];
if (isset($_FILES['foto1']['name']))
$nama_file   = $_FILES['foto1']['name'];
$direktori   = "images/$nama_file";

if (isset($_FILES['foto2']['tmp_name']))
$lokasi_file2 = $_FILES['foto2']['tmp_name'];
if (isset($_FILES['foto2']['type']))
$tipe_file2   = $_FILES['foto2']['type'];
if (isset($_FILES['foto2']['name']))
$nama_file2   = $_FILES['foto2']['name'];
$direktori2   = "images/$nama_file2";

if (isset($_FILES['foto3']['tmp_name']))
$lokasi_file3 = $_FILES['foto3']['tmp_name'];
if (isset($_FILES['foto3']['type']))
$tipe_file3   = $_FILES['foto3']['type'];
if (isset($_FILES['foto3']['name']))
$nama_file3   = $_FILES['foto3']['name'];
$direktori3   = "images/$nama_file3";

if (isset($_FILES['foto4']['tmp_name']))
$lokasi_file4 = $_FILES['foto4']['tmp_name'];
if (isset($_FILES['foto4']['type']))
$tipe_file4   = $_FILES['foto4']['type'];
if (isset($_FILES['foto4']['name']))
$nama_file4   = $_FILES['foto4']['name'];
$direktori4   = "images/$nama_file4";



if(!$keterangan || !$alamat || !$jenis_id || !$harga || !$jenis || !$kota_kabupaten) {
echo ("<SCRIPT LANGUAGE='JavaScript'>
        window.alert('Sepertinya masih ada form yang belum terisi, isi semua form!')
        window.location.href='index.php?page=pasangiklan'
        </SCRIPT>"); 
} else {
move_uploaded_file($lokasi_file,$direktori);
move_uploaded_file($lokasi_file2,$direktori2);
move_uploaded_file($lokasi_file3,$direktori3);
move_uploaded_file($lokasi_file4,$direktori4);
$simpan = mysql_query("INSERT INTO iklan(jenis, judul_iklan, alamat, propinsi_id, kota_id, fasilitas1, fasilitas2, fasilitas3, fasilitas4, banyak_kamar, banyak_kamarmandi, jenis_pembayaran, keterangan, harga, email, foto_iklan, foto_iklan2, foto_iklan3, foto_iklan4, panjang, lebar, tgl_pasang) VALUES('$jenis','$judul_iklan','$alamat','$propinsi_id','$kota_id','$fasilitas1','$fasilitas2','$fasilitas3','$fasilitas4','$banyakkamar','$banyakkamarmandi','$jenis_nama','$keterangan','$harga','$email','$direktori','$direktori2','$direktori3','$direktori4','$panjang','$lebar', NOW())");
if($simpan) {
header ('location:index.php?page=iklansaya');} 

else {
echo "Proses Gagal!";
}
}
  ?>
